import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { FrameTimer } from "../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { TweenLite } from "../../../../com/greensock/TweenLite";
import { Cubic } from "../../../../com/greensock/easing/Cubic";
type int = number;
//class CutCountsView
    
    export  class CutCountsView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.x = 260;
            this.y = 130;
            this.mouseChildren = false;
            this.mouseEnabled = false;
            LoaderManager.instance.load("cutcounts_progress.swf", this.onLoadedComplete);
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._numSp = new Object /* flash.display.Sprite */();
            this._numSp.mouseChildren = false;
            this._numSp.mouseEnabled = false;
            this.addChild(this._numSp);
            this._thousandsDigit = new Object /* flash.display.Bitmap */();
            this._thousandsDigit.x = -170;
            this._thousandsDigit.y = 12;
            this._thousandsDigit.smoothing = true;
            this._numSp.addChild(this._thousandsDigit);
            this._hundredsDigit = new Object /* flash.display.Bitmap */();
            this._hundredsDigit.x = -120;
            this._hundredsDigit.y = 12;
            this._hundredsDigit.smoothing = true;
            this._numSp.addChild(this._hundredsDigit);
            this._tensDigit = new Object /* flash.display.Bitmap */();
            this._tensDigit.x = -70;
            this._tensDigit.y = 12;
            this._tensDigit.smoothing = true;
            this._numSp.addChild(this._tensDigit);
            this._unitsDigit = new Object /* flash.display.Bitmap */();
            this._unitsDigit.x = -20;
            this._unitsDigit.y = 12;
            this._unitsDigit.smoothing = true;
            this._numSp.addChild(this._unitsDigit);
            return;
        }

        /* internal  */onLoadedComplete(arg1: SWFInfo): void
        {
            this._progressBar = arg1.clip;
            this._progressBar.stop();
            this.addChildAt(this._progressBar, 0);
            return;
        }

        public setCutsNum(arg1: int, arg2: int): void
        {
            if (this._num == arg1) 
            {
                return;
            }
            if (arg1 <= 0) 
            {
                this.hide();
                return;
            }
            this.currentInterval = 0;
            this._num = arg1;
            this._lastTime = arg2;
            if (this._numsMc) 
            {
                this.setNums(this._num);
            }
            else 
            {
                LoaderManager.instance.load("cutcountsNums.swf", this.onNumsLoaded);
            }
            if (!this._frameTimer) 
            {
                this._frameTimer = new FrameTimer();
                this._frameTimer.addListener(TimerType.ENTERFRAME, this.onRender);
            }
            this._frameTimer.start();
            if (this.isHide) 
            {
                this.show();
            }
            return;
        }

        /* internal  */onRender(arg1: FrameTimer): void
        {
            this.currentInterval = this.currentInterval + arg1.interval;
            var loc1=this.currentInterval * 340 / 1000 / this._lastTime;
            if (loc1 >= 340) 
            {
                loc1 = 340;
            }
            if (this._progressBar) 
            {
                this._progressBar.gotoAndStop(loc1);
            }
            if (loc1 == 340) 
            {
                this._frameTimer.stop();
                this.currentInterval = 0;
                this.hide();
            }
            return;
        }

        /* internal  */onNumsLoaded(arg1: SWFInfo): void
        {
            this._numsMc = arg1.clip;
            this.setNums(this._num);
            return;
        }

        /* internal  */setNums(arg1: int): void
        {
            var loc5=NaN;
            var loc6=NaN;
            var loc7=NaN;
            var loc1=arg1 % 10000 / 1000;
            var loc2=arg1 % 1000 / 100;
            var loc3=arg1 % 100 / 10;
            var loc4=arg1 % 10;
            this._thousandsDigit.bitmapData = loc1 != 0 ? this.getNumBmd(loc1) : null;
            this._hundredsDigit.bitmapData = loc1 == 0 && loc2 == 0 ? null : this.getNumBmd(loc2);
            this._tensDigit.bitmapData = loc1 == 0 && loc2 == 0 && loc3 == 0 ? null : this.getNumBmd(loc3);
            this._unitsDigit.bitmapData = this.getNumBmd(loc4);
            if (arg1 % 50 == 0) 
            {
                loc5 = 3;
                this._numSp.scaleX = loc5;
                this._numSp.scaleY = loc5;
                if (loc1 > 0) 
                {
                    loc6 = -170 + 100;
                }
                else if (loc2 > 0) 
                {
                    loc6 = -120 + 75;
                }
                else if (loc3 > 0) 
                {
                    loc6 = -70 + 50;
                }
                else if (loc4 > 0) 
                {
                    loc6 = -20 + 25;
                }
                this._numSp.x = loc6 * -1 * (loc5 - 1);
                this._numSp.y = -1 * this._numSp.height * (loc5 - 1) / loc5 / 2;
                TweenLite.to(this._numSp, 0.15, {"x": 0, "y": 0, "scaleX": 1, "scaleY": 1, "ease": Cubic.easeIn});
            }
            return;
        }

        /* internal  */getNumBmd(arg1: int): Object /* flash.display.BitmapData */
        {
            var loc1=null;
            if (CutCountsView.dcBMP[arg1.toString()]) 
            {
                return CutCountsView.dcBMP[arg1.toString()];
            }
            this._numsMc.gotoAndStop(arg1 + 1);
            loc1 = new Object /* flash.display.BitmapData */(100, 100, true, 0);
            loc1.draw(this._numsMc);
            CutCountsView.dcBMP[arg1.toString()] = loc1;
            return loc1;
        }

        public resetPosition(): void
        {
            this.x = 260;
            this.y = 130;
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            if (this._progressBar && this._progressBar.parent) 
            {
                this._progressBar.parent.removeChild(this._progressBar);
            }
            this._progressBar = null;
            if (this._frameTimer) 
            {
                this._frameTimer.dispose();
                this._frameTimer = null;
            }
            return;
        }

        /* internal */ /* var */_progressBar: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_numsMc: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_numSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_thousandsDigit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_hundredsDigit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tensDigit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_unitsDigit: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_frameTimer: FrameTimer;

        /* internal */ /* var */_num: int;

        /* internal */ /* var */_lastTime: int;

        /* internal */ /* var */currentInterval: int=0;

        /* internal */ static /* var */dcBMP: Map<any, any> /* flash.utils.Dictionary */;
    }

            CutCountsView.dcBMP = new Map<any, any> /* flash.utils.Dictionary */();
        